package com.xzy.simple;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author xzy.xiao
 * @date 2022/10/8  19:27
 */
public class Main {
    public static void main(String[] args) throws Exception {
        // 创建容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        // 注册事件监听器
        applicationContext.registerBean("userEventListener1", UserEventListener.class); // Note：事件会被所有相关监听器监听到
        applicationContext.registerBean("userEventListener2", UserEventListener.class);
        applicationContext.refresh();

        // 发布事件
        for (int i = 0; i < 3; i++) {
            UserEventPublisher.sendInsertEvent(applicationContext);
            UserEventPublisher.sendDeleteEvent(applicationContext);
            UserEventPublisher.sendUpdateEvent(applicationContext);

            Thread.sleep(1000);
        }

    }
}
